[XEN] Clean up shutdown handling and ignore opt_noreboot if dom0
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Mon, 7 Aug 2006 14:35:06 +0000 (15:35 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Mon, 7 Aug 2006 14:35:06 +0000 (15:35 +0100)
shuts down cleanly. The option is intended only to retain information
on the local console in case of a crash.

Based on a patch from Muli Ben-Yehuda <muli@il.ibm.com>

Signed-off-by: Keir Fraser <keir@xensource.com>
15 files changed:
xen/arch/ia64/linux-xen/setup.c
xen/arch/powerpc/domain.c
xen/arch/x86/genapic/es7000plat.c
xen/arch/x86/shutdown.c
xen/arch/x86/traps.c
xen/arch/x86/x86_32/traps.c
xen/arch/x86/x86_64/traps.c
xen/common/Makefile
xen/common/domain.c
xen/common/keyhandler.c
xen/common/shutdown.c [new file with mode: 0644]
xen/drivers/char/console.c
xen/drivers/char/serial.c
xen/include/xen/reboot.h [deleted file]
xen/include/xen/shutdown.h [new file with mode: 0644]

index cc8e1970636eacb12c11ac182b385c60fa03273e..6d03910fc71a172705d89d8043ad121eaa369829 100644 (file)
@@ -31,7 +31,7 @@
 #include <linux/console.h>
 #include <linux/delay.h>
 #include <linux/kernel.h>
-#include <linux/reboot.h>
+#include <linux/shutdown.h>
 #include <linux/sched.h>
 #include <linux/seq_file.h>
 #include <linux/string.h>
index 8e4041982fadf2b9aa6c1557881230e86573300b..140b7ec8d2e1b66b44ae0a22e1bcc623f9a89c6d 100644 (file)
@@ -26,7 +26,7 @@
 #include <xen/serial.h>
 #include <xen/domain.h>
 #include <xen/console.h>
-#include <xen/reboot.h>
+#include <xen/shutdown.h>
 #include <asm/htab.h>
 #include <asm/current.h>
 #include <asm/hcalls.h>
index 1d7d0d57768b6c797610d82bc4e9f1a439dc195a..56752061c77f9998978fb003e80de5380cb0f3ba 100644 (file)
@@ -31,7 +31,6 @@
 #include <xen/string.h>
 #include <xen/spinlock.h>
 #include <xen/errno.h>
-#include <xen/reboot.h>
 #include <xen/init.h>
 #include <xen/acpi.h>
 #include <asm/io.h>
index 4f59b2c983908f18568f4da17b0da892d68f4be7..76dbcca5d20d7d432c3ef50e181ee27d4dc8684f 100644 (file)
 #include <xen/smp.h>
 #include <xen/delay.h>
 #include <xen/dmi.h>
+#include <xen/irq.h>
+#include <xen/console.h>
+#include <xen/shutdown.h>
+#include <asm/msr.h>
 #include <asm/regs.h>
 #include <asm/mc146818rtc.h>
 #include <asm/system.h>
 #include <asm/io.h>
 #include <asm/processor.h>
 #include <asm/mpspec.h>
-#include <xen/irq.h>
-#include <xen/console.h>
-#include <asm/msr.h>
-
-/* opt_noreboot: If true, machine will need manual reset on error. */
-static int opt_noreboot = 0;
-boolean_param("noreboot", opt_noreboot);
 
 /* reboot_str: comma-separated list of reboot options. */
 static char __initdata reboot_str[10] = "";
@@ -204,12 +201,6 @@ void machine_restart(char * __unused)
 {
     int i;
 
-    if ( opt_noreboot )
-    {
-        printk("Reboot disabled on cmdline: require manual reset\n");
-        machine_halt();
-    }
-
     watchdog_disable();
     console_start_sync();
 
index 45d73bc51184b40c6ff92ded1d7253a18d4ef0f2..2ce1f00562c9e54c939c0dc5bbaa8642fd50a92d 100644 (file)
@@ -32,7 +32,7 @@
 #include <xen/errno.h>
 #include <xen/mm.h>
 #include <xen/console.h>
-#include <xen/reboot.h>
+#include <xen/shutdown.h>
 #include <asm/regs.h>
 #include <xen/delay.h>
 #include <xen/event.h>
index 3c6d81f21d1baf9deaa2e775edbfc81eb07238c8..4e8c4b075da7c976ed2b14e5ce8fae7ab0878f8d 100644 (file)
@@ -9,7 +9,7 @@
 #include <xen/mm.h>
 #include <xen/irq.h>
 #include <xen/symbols.h>
-#include <xen/reboot.h>
+#include <xen/shutdown.h>
 #include <xen/nmi.h>
 #include <asm/current.h>
 #include <asm/flushtlb.h>
index 6b674a5b5377c3c6685b112404e07411c4fb9b2d..f0fa99349b96f6b1bbd6cafd36ae5cf1f4354617 100644 (file)
@@ -10,7 +10,7 @@
 #include <xen/symbols.h>
 #include <xen/console.h>
 #include <xen/sched.h>
-#include <xen/reboot.h>
+#include <xen/shutdown.h>
 #include <xen/nmi.h>
 #include <asm/current.h>
 #include <asm/flushtlb.h>
index be3179afdcff68cb056c11b0c4c35eaadfada674..4cfde1c83bf7a299901b66e05731f2914c2d53be 100644 (file)
@@ -16,6 +16,7 @@ obj-y += sched_bvt.o
 obj-y += sched_credit.o
 obj-y += sched_sedf.o
 obj-y += schedule.o
+obj-y += shutdown.o
 obj-y += softirq.o
 obj-y += string.o
 obj-y += symbols.o
index c837a31c69fcda8a38a788250043e8cc6a161144..5908a2339971262aeeefcf92c2a09e7e1089d3b7 100644 (file)
@@ -20,6 +20,7 @@
 #include <xen/guest_access.h>
 #include <xen/hypercall.h>
 #include <xen/delay.h>
+#include <xen/shutdown.h>
 #include <asm/debugger.h>
 #include <public/dom0_ops.h>
 #include <public/sched.h>
@@ -282,36 +283,12 @@ static __init int domain_shutdown_finaliser_init(void)
 }
 __initcall(domain_shutdown_finaliser_init);
 
-
 void domain_shutdown(struct domain *d, u8 reason)
 {
     struct vcpu *v;
 
     if ( d->domain_id == 0 )
-    {
-        extern void machine_restart(char *);
-        extern void machine_halt(void);
-
-        debugger_trap_immediate();
-
-        if ( reason == SHUTDOWN_poweroff ) 
-        {
-            printk("Domain 0 halted: halting machine.\n");
-            machine_halt();
-        }
-        else if ( reason == SHUTDOWN_crash )
-        {
-            printk("Domain 0 crashed: rebooting machine in 5 seconds.\n");
-            watchdog_disable();
-            mdelay(5000);
-            machine_restart(0);
-        }
-        else
-        {
-            printk("Domain 0 shutdown: rebooting machine.\n");
-            machine_restart(0);
-        }
-    }
+        dom0_shutdown(reason);
 
     /* Mark the domain as shutting down. */
     d->shutdown_code = reason;
index 3f286e3ae690da11b95cbe086ef3231ffea458bd..21e5862a08ef722cf5362dc5dddba72087018bd8 100644 (file)
@@ -4,7 +4,7 @@
 
 #include <asm/regs.h>
 #include <xen/keyhandler.h> 
-#include <xen/reboot.h>
+#include <xen/shutdown.h>
 #include <xen/event.h>
 #include <xen/console.h>
 #include <xen/serial.h>
diff --git a/xen/common/shutdown.c b/xen/common/shutdown.c
new file mode 100644 (file)
index 0000000..1baea16
--- /dev/null
@@ -0,0 +1,66 @@
+#include <xen/config.h>
+#include <xen/init.h>
+#include <xen/lib.h>
+#include <xen/sched.h>
+#include <xen/domain.h>
+#include <xen/delay.h>
+#include <xen/shutdown.h>
+#include <asm/debugger.h>
+#include <public/sched.h>
+
+/* opt_noreboot: If true, machine will need manual reset on error. */
+int opt_noreboot;
+boolean_param("noreboot", opt_noreboot);
+
+static void maybe_reboot(void)
+{
+    if ( opt_noreboot )
+    {
+        printk("'noreboot' set - not rebooting.\n");
+        machine_halt();
+    }
+    else
+    {
+        printk("rebooting machine in 5 seconds.\n");
+        watchdog_disable();
+        mdelay(5000);
+        machine_restart(NULL);
+    }
+}
+
+void dom0_shutdown(u8 reason)
+{
+    debugger_trap_immediate();
+
+    switch ( reason )
+    {
+    case SHUTDOWN_poweroff:
+    {
+        printk("Domain 0 halted: halting machine.\n");
+        machine_halt();
+        break; /* not reached */
+    }
+
+    case SHUTDOWN_crash:
+    {
+        printk("Domain 0 crashed: ");
+        maybe_reboot();
+        break; /* not reached */
+    }
+
+    case SHUTDOWN_reboot:
+    {
+        printk("Domain 0 shutdown: rebooting machine.\n");
+        machine_restart(NULL);
+        break; /* not reached */
+    }
+
+    default:
+    {
+        printk("Domain 0 shutdown (unknown reason %u): ", reason);
+        maybe_reboot();
+        break; /* not reached */
+    }
+    }
+}  
+
index f5ca219f9c552da74dbcec0c3ac17a5f3ab42f34..1e7f107966603c0f6cacaf4bcc022d0a388bb657 100644 (file)
@@ -21,6 +21,7 @@
 #include <xen/mm.h>
 #include <xen/delay.h>
 #include <xen/guest_access.h>
+#include <xen/shutdown.h>
 #include <asm/current.h>
 #include <asm/debugger.h>
 #include <asm/io.h>
@@ -730,14 +731,24 @@ void panic(const char *fmt, ...)
     printk("Panic on CPU %d:\n", smp_processor_id());
     printk(buf);
     printk("****************************************\n\n");
-    printk("Reboot in five seconds...\n");
+    if ( opt_noreboot )
+        printk("Manual reset required ('noreboot' specified)\n");
+    else
+        printk("Reboot in five seconds...\n");
     spin_unlock_irqrestore(&lock, flags);
 
     debugger_trap_immediate();
 
-    watchdog_disable();
-    mdelay(5000);
-    machine_restart(0);
+    if ( opt_noreboot )
+    {
+        machine_halt();
+    }
+    else
+    {
+        watchdog_disable();
+        mdelay(5000);
+        machine_restart(NULL);
+    }
 }
 
 void __bug(char *file, int line)
index 4ee52378040196785d4055a83a0ea1fd7f8d2803..93bb556204f2bf486a599300f1023a1a023550da 100644 (file)
@@ -11,7 +11,6 @@
 #include <xen/init.h>
 #include <xen/irq.h>
 #include <xen/keyhandler.h> 
-#include <xen/reboot.h>
 #include <xen/sched.h>
 #include <xen/serial.h>
 
diff --git a/xen/include/xen/reboot.h b/xen/include/xen/reboot.h
deleted file mode 100644 (file)
index 8ef2d96..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef _LINUX_REBOOT_H
-#define _LINUX_REBOOT_H
-
-extern void machine_restart(char *cmd);
-extern void machine_halt(void);
-extern void machine_power_off(void);
-
-#endif /* _LINUX_REBOOT_H */
diff --git a/xen/include/xen/shutdown.h b/xen/include/xen/shutdown.h
new file mode 100644 (file)
index 0000000..cfe2000
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef __XEN_SHUTDOWN_H__
+#define __XEN_SHUTDOWN_H__
+
+/* opt_noreboot: If true, machine will need manual reset on error. */
+extern int opt_noreboot;
+
+void dom0_shutdown(u8 reason);
+
+void machine_restart(char *cmd);
+void machine_halt(void);
+void machine_power_off(void);
+
+#endif /* __XEN_SHUTDOWN_H__ */